import  request  from '@/utils/request'
import {defineStore} from 'pinia'
import { BannerItem, GoodItem, HotGoods, IApiRes } from '@/types/data'


export default defineStore('home', {
  state() {
    return {
      bannerList: [] as BannerItem[],//轮播图数据
      newGoodList: [] as GoodItem[], //新鲜好物数据
      newHotList: [] as HotGoods[] //人气推荐数据
    }
  },
  actions: {
    // 获取轮播图数据
    async getBannerList() {
      const res = await request.get<IApiRes<BannerItem[]>>('/home/banner')
      // console.log(res)
      this.bannerList =  res.data.result
    },
    // 获取新鲜好物数据
    async getNewList() {
      const res = await request.get<IApiRes<GoodItem[]>>('/home/new')
      // console.log('getNewList', res);
      this.newGoodList =  res.data.result
    },
    // 获取人气推荐数据
    async getHotList() {
      const res = await request.get<IApiRes<HotGoods[]>>('/home/hot')
      this.newHotList =  res.data.result
    }
  }
})

